﻿using EFCore.Context;
using IResoitory;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Resoitory
{
    //仓储层_用户表接口实现类
    public class UserRepository :BaseRepository<User>,IUserRepository
    {
        private readonly EducationContext _context;

        public UserRepository(EducationContext context)
        {
            base.context = context;
            _context = context;
        }
        //用户登录验证
        public override async Task<bool> islogin(string uid, string pwd)
        {
            var result = await _context.Set<User>().Where(o => o.UserPhone == uid && o.Pwd == pwd).FirstOrDefaultAsync();
            if (result != null)
            {
                return true;
            }
            return false;
        }
        //添加到分组
        public async Task<bool> onAddGroup(int userId,int groupId)
        {   
            //根据ID查找要添加的分组的信息
            var result = await _context.Set<User>().FindAsync(userId);
            result.GroupId = groupId;
            return await _context.SaveChangesAsync() > 0;
        }
        //从分组中删除
        public override async Task<bool> onDelete(int id)
        {
            var result = await _context.Set<User>().FindAsync(id);
            result.GroupId = 0;
            return await _context.SaveChangesAsync() > 0;
        }
    }
}
